<template>
  <view class="group-list" ref="container">
    <!-- <view class="header">
      <image src="@/static/images/group.png" class="image" />
    </view>-->
    <view class="list" v-if="combinationList.length>0">
      <view
        class="item acea-row row-between-wrapper"
        v-for="(item, combinationListIndex) in combinationList"
        :key="combinationListIndex"
        @click="link(item)"
      >
        <view class="pictrue">
          <image :src="item.image" />
        </view>
        <view class="text">
          <view class="line1" v-text="item.title"></view>
          <view class="acea-row">
            <view class="team acea-row row-middle cart-color">
              <view class="iconfont icon-pintuan"></view>
              <view class="num" v-text="item.people + '人团'"></view>
            </view>
          </view>
          <view class="bottom acea-row row-between-wrapper">
            <view class="money">
              ￥
              <text class="num" v-text="item.pinkPrice"></text>
              <text class="y-money" v-text="'￥' + item.productPrice"></text>
            </view>
            <view class="groupBnt bg-color-red">
              去拼团
              <text class="iconfont icon-jiantou"></text>
            </view>
          </view>
        </view>
      </view>
      <Loading :loaded="status" :loading="loadingList"></Loading>
    </view>
    <view class="noCommodity" style="background-color: #fff;" v-if="combinationList.length === 0">
      <view class="noPictrue">
        <image src="@/static/images/noGood.png" class="image" />
      </view>
    </view>
  </view>
</template>
<script>
import { getCombinationList } from "@/api/activity";
import Loading from "@/components/Loading";

export default {
  name: "GoodsGroup",
  components: {
    Loading
  },
  props: {},
  data: function() {
    return {
      combinationList: [],
      status: false, //砍价列表是否获取完成 false 未完成 true 完成
      loading: false, //当前接口是否请求完成 false 完成 true 未完成
      page: 1, //页码
      limit: 20, //数量
      loadingList: false
    };
  },
  mounted: function() {
    // document.querySelector('body').setAttribute('style', 'background-color:#00c17b');
    this.getCombinationList();
  },
  onReachBottom() {
    !this.loadingList && this.getCombinationList();
  },
  methods: {
    getCombinationList: function() {
      var that = this;
      if (that.loading) return;
      if (that.status) return;
      getCombinationList({ page: that.page, limit: that.limit }).then(res => {
				
        that.status = res.data.length < that.limit;
        that.combinationList.push.apply(that.combinationList, res.data);
				console.log(JSON.stringify(that.combinationList));
        that.page++;
        that.loading = false;
      });
    },
    link: function(item) {
			var obj=new Date();
			var time = obj.getTime();
			let id = item.id;
			//当前时间小于结束时间
			if(time < item.endTimeDate){
				this.$yrouter.push({
				        path: "/pages/activity/GroupDetails/index",
				        query: { id }
				      });
			}else{
				uni.showToast({
				  title: "商品已结束，请刷新",
				  icon: "none",
				  duration: 2000
				});
			}
		}
  }
};
</script>
